package com.usian.user.service.impl;

import com.github.pagehelper.PageInfo;
import com.usian.common.dto.CourseDto;
import com.usian.common.pojo.Catalogue;
import com.usian.common.pojo.Cou;
import com.usian.common.pojo.Lab;
import com.usian.common.pojo.ProgressData;
import com.usian.common.vo.PageResponseResult;
import com.usian.common.vo.ResponseResult;
import com.usian.user.feign.CourseFeign;
import com.usian.user.mapper.CourseMapper;
import com.usian.user.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseFeign courseFeign;

    @Override
    public ResponseResult getCourseList(CourseDto courseDto) {
        System.out.println("===========" + courseDto);
        PageInfo<Cou> pageInfo = courseFeign.getCourseList(courseDto);
        PageResponseResult responseResult = new PageResponseResult();
        responseResult.setPageSize(pageInfo.getSize());
        responseResult.setCurrentPage(pageInfo.getPageNum());
        responseResult.setTotal((int) pageInfo.getTotal());
        responseResult.setData(pageInfo.getList());
        System.out.println("=============" + responseResult);
        return responseResult;
    }

    @Override
    public ResponseResult getLab() {
        List<Lab> labList = courseFeign.getLab();
        return ResponseResult.okResult(labList);
    }

    @Override
    public ResponseResult getNewestCourseList(CourseDto courseDto) {
        System.out.println("===========" + courseDto);
        PageInfo<Cou> pageInfo = courseFeign.getNewestCourseList(courseDto);
        PageResponseResult responseResult = new PageResponseResult();
        responseResult.setPageSize(pageInfo.getSize());
        responseResult.setCurrentPage(pageInfo.getPageNum());
        responseResult.setTotal((int) pageInfo.getTotal());
        responseResult.setData(pageInfo.getList());
        System.out.println("=============" + responseResult);
        return responseResult;
    }

    @Override
    public ResponseResult getHotCourseList(CourseDto courseDto) {
        System.out.println("===========" + courseDto);
        PageInfo<Cou> pageInfo = courseFeign.getHotCourseList(courseDto);
        PageResponseResult responseResult = new PageResponseResult();
        responseResult.setPageSize(pageInfo.getSize());
        responseResult.setCurrentPage(pageInfo.getPageNum());
        responseResult.setTotal((int) pageInfo.getTotal());
        responseResult.setData(pageInfo.getList());
        System.out.println("=============" + responseResult);
        return responseResult;
    }

    @Override
    public ResponseResult getCourseById(Integer courseId) {
        Cou cou = courseFeign.getCourseById(courseId);
        return ResponseResult.okResult(cou);
    }

    @Override
    public ResponseResult getProgressData(Integer courseId,Integer userId) {
        ProgressData data = courseFeign.getProgressData(courseId,userId);
        return ResponseResult.okResult(data);
    }

    @Override
    public ResponseResult getCatalogue(Integer courseId) {
        List<Catalogue> catalogueList = courseFeign.getCatalogue(courseId);
        return ResponseResult.okResult(catalogueList);
    }

    @Override
    public ResponseResult setProgress(Integer cataId, Integer userId, Integer courseId) {
        courseFeign.setProgress(cataId,userId,courseId);
        return ResponseResult.okResult("成功");
    }
}
